import { defHttp } from '@/utils/http/axios';
import { PageResult, Result } from '@/api/model/baseModel';
import { ProductVo } from './model';

const PREFIX = '/basedata/product';
const region = 'cloud-api';

export const bomProductApi = {
  /**
   * 查询商品
   */
  query: (params?: any) => {
    return defHttp.get<PageResult<ProductVo>>(
      {
        url: PREFIX + '/query',
        params,
      },
      {
        region,
      },
    );
  },

  /**
   * 新增物料
   */
  addMaterial: (data: any) => {
    return defHttp.post<Result<void>>(
      {
        url: '/bom/addMaterial',
        data,
      },
      {
        region,
      },
    );
  },

  /**
   * 查询物料列表
   */
  queryMaterialPage: (data: any) => {
    return defHttp.post<PageResult<any>>(
      {
        url: '/bom/queryMaterialPage',
        data,
      },
      {
        region,
      },
    );
  },

  /**
   * 删除物料
   */
  deleteMaterial: (id: string) => {
    return defHttp.delete<Result<void>>(
      {
        url: `/bom/deleteMaterial/${id}`,
      },
      {
        region,
      },
    );
  },

  /**
   * 更新物料
   */
  updateMaterial: (queryParams: any) => {
    console.log('更新物料请求参数:', queryParams);
    return defHttp.post<Result<void>>(
      {
        url: `/bom/updateMaterial`,
        params: queryParams,
      },
      {
        region,
      },
    );
  },

  /**
   * 查询工序列表
   */
  queryProcessPage: (params?: any) => {
    return defHttp.post<PageResult<any>>(
      {
        url: '/bom/queryProcessesPage',
        params,
      },
      {
        region,
      },
    );
  },

  /**
   * 新增工序
   */
  addProcess: (data: any) => {
    return defHttp.post<Result<void>>(
      {
        url: '/bom/addProcesses',
        data,
      },
      {
        region,
      },
    );
  },

  /**
   * 删除工序
   */
  deleteProcesses: (id: string) => {
    return defHttp.get<Result<void>>(
      {
        url: `/bom/deleteProcesses/${id}`,
      },
      {
        region,
      },
    );
  },

  /**
   * 修改工序
   */
  updateProcess: (data: any) => {
    return defHttp.post<Result<void>>(
      {
        url: `/bom/updateProcesses`,
        data,
      },
      {
        region,
      },
    );
  },
};
